{% set pypi_name = 'neutron-fwaas-dashboard' %}
{% set source = fetch_source('https://tarballs.openstack.org/neutron-fwaas-dashboard/neutron-fwaas-dashboard-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}

%if 0%{?rhel} || 0%{?fedora}
%global http_dashboard_dir %{_datarootdir}/openstack-dashboard
%else
%global http_dashboard_dir /srv/www/openstack-dashboard
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        Neutron FWaaS management plugin for Horizon
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/neutron-fwaas-dashboard
Source0:        {{ source|basename }}
BuildRequires:  fdupes
BuildRequires:  gettext
BuildRequires:  {{ py3('horizon') }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('ddt') }}
BuildRequires:  {{ py3('django-nose') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('python-subunit') }}
BuildRequires:  {{ py3('reno') }}
BuildRequires:  {{ py3('testscenarios') }}
BuildRequires:  {{ py3('testtools') }}
Requires:       {{ py3('horizon-plugin-neutron-fwaas-ui') }} = %{version}
BuildArch:      noarch

%description
OpenStack Neutron FWaaS management plugin for Horizon.

%package -n    {{ py3('horizon-plugin-neutron-fwaas-ui') }}
Summary:       Neutron FWaaS Management Plugin for Horizon - Python module
Requires:      {{ py3('Django') }}
Requires:      {{ py3('python-neutronclient') }}
Requires:      {{ py3('pbr') }}

%description -n {{ py3('horizon-plugin-neutron-fwaas-ui') }}
OpenStack Neutron FWaaS management plugin for Horizon.

This package contains the core Python module of the neutron-fwaas-ui.

%package test
Summary:       Neutron FWaaS Management Plugin for Horizon - Testsuite
Requires:      {{ py3('ddt') }}
Requires:      {{ py3('django-nose') }}
Requires:      {{ py3('mock') }}
Requires:      {{ py3('openstackdocstheme') }}
Requires:      {{ py3('python-subunit') }}
Requires:      {{ py3('reno') }}
Requires:      {{ py3('testscenarios') }}
Requires:      {{ py3('testtools') }}

%description test
OpenStack Neutron FWaaS management plugin for Horizon.
It is used to verify the functionality of the Neutron FWaaS UI Plugin.

%prep
%autosetup -n {{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

%build
%{py3_build}
pushd neutron_fwaas_dashboard
PYTHONPATH=%{http_dashboard_dir} python3 ../manage.py compilemessages
popd

%check
# Depends on Selenium integration tests, we just want unit tests
rm -rf neutron_fwaas_dashboard/test/integration
PYTHONPATH=%{http_dashboard_dir} python3 manage.py test neutron_fwaas_dashboard \
    --settings=neutron_fwaas_dashboard.test.settings \
    --exclude-tag integration

%install
%{py3_install}

install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/
cp -a neutron_fwaas_dashboard/enabled/_70*.py* %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/
install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/conf/
cp -a etc/neutron-fwaas-policy.json %{buildroot}%{http_dashboard_dir}/openstack_dashboard/conf/

%fdupes %{buildroot}%{python3_sitelib}
%fdupes %{buildroot}%{http_dashboard_dir}

%post
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%postun
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%files
%doc ChangeLog CONTRIBUTING.rst README.rst
%license LICENSE
%{http_dashboard_dir}/openstack_dashboard/enabled/_70*.py*
%{http_dashboard_dir}/openstack_dashboard/conf/neutron-fwaas-policy.json

%files -n {{ py3('horizon-plugin-neutron-fwaas-ui') }}
%doc README.rst
%license LICENSE
%{python3_sitelib}/neutron_fwaas_dashboard/
%{python3_sitelib}/neutron_fwaas_dashboard-*.egg-info
%exclude %{python3_sitelib}/neutron_fwaas_dashboard/test*

%files test
%{python3_sitelib}/neutron_fwaas_dashboard/test*

%changelog
